package com.dindang.propertyfee.mvp.ui.adapter.custom;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dindang.propertyfee.R;
import com.dindang.propertyfee.app.utils.TextViewUtils;
import com.dindang.propertyfee.mvp.model.entity.PropertyCharge;
import com.dindang.propertyfee.mvp.ui.activity.PaymentDetailsActivity;

import java.util.List;

/**物业逾期适配器*/
public class RecentBillViewAdapter extends RecyclerView.Adapter<RecentBillViewAdapter.ViewHolder> {
    List<PropertyCharge.RecentBill.Rows> list;
    OnClickListener listener;
    public RecentBillViewAdapter(List<PropertyCharge.RecentBill.Rows> list, OnClickListener listener) {
        this.list = list;
        this.listener = listener;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.propertyfee_item_recent_bill, parent, false);
        RecentBillViewAdapter.ViewHolder viewHolder = new RecentBillViewAdapter.ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        PropertyCharge.RecentBill.Rows recentBill = list.get(position);
        holder.tv_address.setText(recentBill.addr);
        holder.tv_total.setText(TextViewUtils.getAmount(recentBill.amount));
        holder.tv_name_phone.setText(recentBill.bName);

        holder.constraintlayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(holder.constraintlayout.getContext(), PaymentDetailsActivity.class);
//                holder.constraintlayout.getContext().startActivity(intent);
                listener.onClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        ConstraintLayout constraintlayout;
        TextView tv_address;
        TextView tv_total;
        TextView tv_name_phone;
        ViewHolder(View itemView) {
            super(itemView);
            constraintlayout = itemView.findViewById(R.id.propertyfee_constraintlayout);
            tv_address = itemView.findViewById(R.id.propertyfee_tv_address);
            tv_total = itemView.findViewById(R.id.propertyfee_tv_total);
            tv_name_phone = itemView.findViewById(R.id.propertyfee_tv_name_phone);
        }
    }

    public interface OnClickListener{
        void onClick(int position);
    }

}